#include"Number.h"

 int LuckyNumber::generate(std::string animal) {
    if (numbers.find(animal) == numbers.end()) {
        std::cout << "It isn't in the map" << std::endl;
        return 0;
    }
    else {
        std::cout << "Using Network generate!!!" << std::endl;
        return numbers[animal];
    }
}

bool LuckyNumber::add(std::string animal, int number)
{
    if (this->exist(animal)) {
        std::cout << "It is already in the map" << std::endl;
        return false;
    }
    else {
        this->numbers.insert(std::pair<std::string, int>(animal, number));
        std::cout << "Add success!!!" << std::endl;
        return true;
    }
}

bool LuckyNumber::del(std::string animal)
{
    if (this->exist(animal)) {
        this->numbers.erase(animal);
        std::cout << "Delete success!!!" << std::endl;
        return true;
    }
    else {
        std::cout << "It isn't in the map" << std::endl;
        return false;
    }
}

bool LuckyNumber::change(std::string animal, std::string Newanimal, int Newnumber)
{
    if (!this->exist(animal)) {
        std::cout << "It isn't in the map" << std::endl;
        return false;
    }
    else if (Newanimal != animal && this->exist(Newanimal)) {
        std::cout << "The target is already in the map" << std::endl;
        return false;
    }
    else {
        this->numbers.erase(animal);
        this->numbers.insert(std::pair<std::string, int>(Newanimal, Newnumber));
        std::cout << "Change success!!!" << std::endl;
        return true;
    }
}

bool LuckyNumber::change(std::string animal, int Newnumber)
{
    return change(animal, animal, Newnumber);
}

bool LuckyNumber::exist(std::string animal) const
{
    if (numbers.find(animal) == numbers.end())
        return false;
    else 
        return true;
}
